The present invention relates to a unique operating system for a process controller.
Process controllers are used to perform a variety of functions including process control functions and data-gathering functions. Process control functions include the monitoring of various conditions, such as liquid and gas pressures, flows, temperatures, etc., and responding to the state of the conditions by selectively activating pumps, valves, etc. to control the monitored conditions. The process control functions relate to such applications as oil and natural gas production and distribution, industrial plant control, etc. The data-gathering functions of process controllers allow a historical record of data relating to such variables as pressures or flows to be made over an extended period of time, such as several weeks or months, for example.
Typically, a number of process controllers are used in a computer system or network having a central host computer. For example, a single host computer may communicate with as few as 10 to more than 100 process controllers.
A process controller typically has a number of input/output (I/O) circuits which may be of four basic types: a digital input circuit, a digital output circuit, an analog input circuit, and an analog output circuit. The digital I/O circuits are used to monitor and control conditions and/or devices having only two states, on and off for example. The analog I/O circuits are used where the condition or device has many states. For example, an analog input circuit may be used to input the temperature of a liquid in a tank to the process controller, and an analog output circuit may be used to control the position of a valve having many positions.
The operating system of a conventional process controller may be a multi-tasking system that performs a number of different tasks at one or more desired rates or intervals. A flowchart of a prior art operating system for a process controller is shown in FIG. 1. Referring to FIG. 1, the operating system performs a number of tasks, which may be implemented as one or more computer program routines executed by a microprocessor. These tasks include a system task 1 that performs various conventional system functions such as a watchdog timer function, etc. A database task 2 is executed to update the database stored in the process controller. A process task 3 is performed to periodically make calculations relating to the control one or more processes under the control of the process controller. This control may be conventional PID control, for example.
The tasks 4-7 relate to the communication between the microprocessor of the process controller and the I/O circuits inside the process controller. A read digital inputs (DIS) task 4 causes the process controller to read the digital value input to each of its DI circuits. A read analog inputs (AIS) task 5 causes the process controller to read the analog value input to each of its AI circuits. A write digital outputs (DOS) task 6 causes the process controller to write a digital output value to each of its DO circuits. Finally, a write analog outputs (AOS) task 7 causes the I/O controller to write an analog output value to each of its AO circuits.
A communication task 8 is executed to perform communication between the process controller and the host computer. Communication may also be performed with other devices. A compute flow task 9 may be performed to make flow calculations for particular applications.
The tasks generally described above are probably performed by most conventional process controllers since they define the basic operation of such a controller. However, all of the tasks must be performed in such a manner as to minimize the period of time between each successive execution of each of the tasks.
The operating system of FIG. 1 functions in the following manner. Each of the tasks 1-9 is broken up into a sequence of "micro-tasks." For example, the system task 1 might be subdivided into 20 such micro-tasks. The operating system performs one micro-task in each of the tasks 1-9 at a time. Thus, the operating system begins by performing the first micro-task of each of the tasks 1-9 in that order, and then the second micro-task in each of the tasks 1-9, and so on.
The detailed operation of the system of FIG. 1 begins at step 10, where the value of a flag TICK is tested to determine whether it is 1. The TICK flag is set to 1 by a software counter every 10 milliseconds (ms). If TICK is 1, the program branches to step 11 where a TASK variable is set to 1. The TASK variable stores the number of the current task, for example one of the numbers 1-9 for the tasks 1-9 shown, for which a micro-task is to be performed. At step 12, the value of the TASK variable is tested to determine whether the micro-task for the last task (TASK=9) has been performed. If that micro-task has been performed, the program branches to step 13 where the value of the TICK flag is set to 0. The program then branches to step 10 where it waits until the software counter sets the TICK flag to 1 at the next 10 ms interval.
If the micro-task for the last task has not yet been performed as determined by step 12, the program branches to step 14 where a timer for the current task is tested to determine whether it is 0. Each of the nine tasks has such a timer. The timer controls how often each of the tasks is to be performed. Upon the completion of each task, its associated timer is initialized to a predetermined value depending upon how often that task should be performed. The value stored in the timer is decremented by 1 each time the software counter sets the TICK flag to 1. Thus, to perform a task most frequently, the timer associated with that task would be initialized to one, whereas to perform a task infrequently, its timer would be set to a relatively large number, such as 200.
If the timer associated with the current task is zero, indicating that it is time to perform a micro-task for that task, the program branches to the current task, as determined by the value of the TASK variable. After performing a micro-task for that task, the program branches to step 15, where the current value of the TASK variable is incremented by one. Steps 12 and 14 are then repeated until a micro-task has been performed for each of the tasks 1-9. At that point, the program branches step 10. The program continues to repeat in the manner described above to perform successive micro-tasks for each of the tasks 1-9.
As should be appreciated from the above description, the operating system executes all of tasks "in parallel," since portions of all of the tasks are performed each time the TICK flag is set to 1.
Although the operating system described generally above is satisfactory, it has a number of disadvantages. One disadvantage is that an undue amount of time is wasted during the waiting step 10. In particular, the operating system was designed so that the combined execution time of nine micro-tasks, one micro-task for each of the tasks 1-9, would be slightly less than 10 ms, 9.5 ms for example. Thus, the program would only wait at step 10 for 0.5 ms since the TICK flag is set to 1 every 10 ms. However, the execution time of the micro-tasks of the main tasks 1-9 is somewhat unpredictable. As a result, in some cases the total execution time is greater than 10 ms, 10.5 ms for example. In this case, the program would have to wait at step 10 for 9.5 ms before the TICK flag was set to 1 by the next tick of the 10 ms software counter. This waiting period would represent nearly 50% of the total execution time, a significant waste of time.
Another disadvantage of the above operating system is that a large amount of overhead and system housekeeping are required to execute each task due to the nature of the execution. In particular, the execution of each of the tasks by intermittently performing a number of micro-tasks requires an unduly complicated computer program which takes longer to execute and requires more memory for storage. Another disadvantage of the above system is that it lacks flexibility in assigning priority to each of the tasks.